# import sys
# from pathlib import Path
# sys.path.append(str(Path(__file__).resolve().parents[1]))
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from LeetCoder import *
class Solution:
    def countTime(self, time: str) -> int:
        t = [time[i] for i in range(len(time)) if i !=2]
        ans = 0
        def f(i):
            if i == len(t):
                if (int(t[0])*10 + int(t[1])) < 24 and (int(t[2])*10 + int(t[3])) < 60:
                   nonlocal ans
                   ans+=1
                return
            if t[i]!='?':
                f(i+1)
            else:
                for j in range(10):
                    t[i] = str(j)
                    f(i+1)
                t[i] = '?'
        f(0)
        return ans

s = Solution()
print(s.countTime("?5:00")==2)
print(s.countTime("0?:0?")==100)
print(s.countTime("??:??")==1440)


class Solution:
    def countTime(self, time: str) -> int:
        def hour(x,y):
            if x !='?' and y !='?':
                return 1
            if x == '?' and y =='?':
                return 24
            if x == '?':
                if int(y) > 3:
                    return 2
                else:
                    return 3
            if int(x) == 2:
                return 4
            return 10
        def minute(x,y):
            if x !='?' and y !='?':
                return 1
            if x =='?' and y =='?':
                return 60
            if x == '?':
                return 6
            return 10
        return hour(time[0],time[1]) * minute(time[3],time[4])

s = Solution()
print(s.countTime("?5:00")==2)
print(s.countTime("0?:0?")==100)
print(s.countTime("??:??")==1440)
print(s.countTime("2?:??")==240)